﻿using UnityEngine;

[RequireComponent(typeof(Rigidbody2D))]
public class RoleMove : MonoBehaviour
{
    private Rigidbody2D rb;

    public float speed = 1;

    private float horizontal;
    private float vertical;
    private Vector2 v;

    private void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    private void Update()
    {
        horizontal = Input.GetAxis("Horizontal");
        vertical = Input.GetAxis("Vertical");
        v = speed * new Vector3(horizontal, vertical, 0f).normalized;
        rb.linearVelocity = v;
    }
}